home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’97
/
Crash & Burn
/
source code
/
CrashBurnPatchMain.cpp
next >
Wrap
C/C++ Source or Header
|
1997-06-27
|
2KB
|
96 lines
#include "patches.h"
#include <traps.h>
#include <lowmem.h>
static asm long* GetOldDebugUtilStorage()
{
lea _oldDebugUtilStorage,a0
rts
_oldDebugUtilStorage:
dc.l 0x00000000
}
static asm long* GetCountStorage()
{
lea _countStorage,a0
rts
_countStorage:
dc.l 0x00000000
}
static asm long* GetProcStorage()
{
lea _procStorage,a0
rts
_procStorage:
dc.l 0x00000000
}
static long Poll(short selector)
{
long continueQ = true;
long* count = GetCountStorage();
if(selector == 3){
long* procStore = GetProcStorage();
ProcPtr p = (ProcPtr)*procStore;
if(p != NULL){
(*p)();
}
}
return continueQ;
}
static asm void newDebugUtil()
{
subq.l #4,a7 // reserve space for old trap address
move.l a0,-(a7) // save a0
movem.l a1-a5/d0-d7,-(a7) // save everything else
move.w d0,-(a7)
jsr Poll
addq.l #2,a7
tst.w d0
bne.s _Continue
movem.l (a7)+,a1-a5/d0-d7
move.l (a7)+,a0
addq.l #4,a7
rts
_Continue:
movem.l (a7)+,a1-a5/d0-d7 // restore registers
jsr GetOldDebugUtilStorage // get original trap address storage in a0
move.l (a0),a0 // get original trap address value into a0
move.l a0,4(a7) // stuff old trap onto stack
move.l (a7)+,a0 // restore original a0
rts // rts to jump to old trap.
}
pascal void main(ProcPtr inIdleProc)
{
long* procStore = GetProcStorage();
*procStore = (long)inIdleProc;
long* debugUtilStorage = GetOldDebugUtilStorage();
*debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
}